import { Module } from 'vuex';
import { GlobalDataProps } from './index';

export type TemplateProps = Required<Omit<any, 'props' | 'setting'>>;
export interface TemplatesProps {
  data: any[];
  totalTemplates: number;
  works: any[];
  totalWorks: number;
}

const templates: Module<TemplatesProps, GlobalDataProps> = {
  state: {
    data: [],
    totalTemplates: 0,
    works: [],
    totalWorks: 0
  },
  mutations: {},
  actions: {},
  getters: {
    getTemplateById: (state, getters, rootState) => (id: number) => {
      return state.data.find(t => t.id === id);
    }
  }
};

export default templates;
